//
//  choiceDayViewController.m
//  We_Travel
//
//  Created by lanou3g on 15/12/16.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "choiceDayViewController.h"
#import "DayView.h"

@interface choiceDayViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic , strong) DayView *dayView;
@property (nonatomic , strong) NSMutableArray *dataArray;
@end

@implementation choiceDayViewController

- (void)loadView
{
    self.dayView = [[DayView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.view = self.dayView;
    self.dayView.backgroundColor = [UIColor brownColor];
    self.dayView.tableView.backgroundColor = [UIColor cyanColor];
}

- (void)loadData
{
    for (int i = 1; i < 31; i++) {
        NSString *str = [NSString stringWithFormat:@"%d天",i];
        [self.dataArray addObject:str];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dayView.tableView.delegate = self;
    self.dayView.tableView.dataSource = self;
    [self loadData];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"dayCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.textLabel.text = [self.dataArray objectAtIndex:indexPath.row];
    cell.backgroundColor = [UIColor cyanColor];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 80;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{
    return self.dataArray.count;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"选择天数";
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *string =[NSString stringWithFormat:@"%ld",indexPath.row + 1];
    self.block(string);
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (NSMutableArray *)dataArray
{
    if (_dataArray == nil) {
        self.dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

@end
